package com.shopowner.controller;

import com.shopowner.dto.DTO;
import com.shopowner.entity.Field;
import com.shopowner.page.PageInfo;
import com.shopowner.service.FieldService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@CrossOrigin
@Controller
@RequestMapping("/fieldController")
public class FieldController {
	@Resource
	FieldService fieldService;
	@RequestMapping("/getAllField")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Field> getAllField() throws Exception {
    	System.out.println("查询全部店长");
		return fieldService.getAllFields();
    }
	@RequestMapping("/selectFieldByFno/{fno}")
	@ResponseBody
	public DTO<Field> selectFieldByFno(@PathVariable("fno") String fno) throws Exception {
		System.out.println("根据主键查询");
		return fieldService.selectFieldByFno(fno);
	}
	@RequestMapping("/deleteFieldByFno/{fno}")
	@ResponseBody
    public DTO<Field> deleteFieldByFno(@PathVariable("fno") String fno) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(fno+"删除店长");
    	return fieldService.deleteFieldByFno(fno);
    }

	@RequestMapping("/updateFieldByFno")
	@ResponseBody
	public DTO<Field> updateFieldByFno(@RequestBody Field field) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改店长");
		return fieldService.updateFieldByFno(field);
	}


	@RequestMapping("/addField")
	@ResponseBody
	public DTO<Field> addField(@RequestBody Field field) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加店长");
		System.out.println(field);
 		return fieldService.addField(field);
	}

	@RequestMapping("/getFieldByPage")
	@ResponseBody
	public DTO<Field> getFieldByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页店长");
		return fieldService.getFieldByPage(pageInfo);
	}


}